package com.ktwlsoft.fundmanage.controller;

import com.ktwlsoft.fundmanage.domain.business.FundInService;
import com.ktwlsoft.fundmanage.domain.entity.FundSuperviseAccept;
import com.ktwlsoft.fundmanage.domain.entity.RelationalPersonBank;
import com.ktwlsoft.fundmanage.payload.fundIn.DrawMoneyOutAccountLedgerPageRequest;
import com.ktwlsoft.fundmanage.payload.fundIn.FindBusinessPageRequest;
import com.ktwlsoft.fundmanage.payload.fundIn.PaymentAccountEntryLedgerPageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
 * 资金流入控制器，涵盖所有资金流入相关的查询Api
 *
 * @author LanJian
 */
@Api(description = "业务办理、资金缴款相关查询, 作者：朱和")
@RestController
@RequestMapping("/fundIn")
public class FundInController {

    private final FundInService fundInService;

    public FundInController(FundInService fundInService) {
        this.fundInService = fundInService;
    }

    /**
     * 查看此业务是否已存在
     *
     * @param tsCode 业务受理编号
     * @return 受理成功的实体信息
     */
    @ApiOperation(value = "查看业务是否")
    @GetMapping("/{tsCode}/businessExist")
    public ResponseEntity<?> businessExist(@PathVariable Long tsCode) {
        return ResponseEntity.ok(fundInService.businessExist(tsCode));
    }

    /**
     * 更新编辑业务
     *
     * @param fundSuperviseAccept 业务受理实体
     * @return 更新后的业务实体
     */
    @ApiOperation("业务编辑更新，注意必传tsCode, 作者：兰坚")
    @PutMapping("/updateBusiness")
    public ResponseEntity<?> updateBusiness(@RequestBody FundSuperviseAccept fundSuperviseAccept) {
        if (fundSuperviseAccept.getTsCode() == 0) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("TsCode is required!");
        }
        return ResponseEntity.ok(fundInService.updateBusiness(fundSuperviseAccept));
    }

    /**
     * 查看业务受理详情
     *
     * @param tsCode 交易编号
     * @return 业务详情
     */
    @ApiOperation(value = "查看业务受理详情", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @GetMapping("/getBusiness")
    public ResponseEntity<?> getBusiness(Long tsCode) {
        return ResponseEntity.ok(fundInService.findBusiness(tsCode));
    }

    /**
      * 查看案件详情 on 2019/9/5 9:56
      *
      * @param tsCode tsCode
      * @return ResponseEntity<?>
      */
    @ApiOperation(value = "查看案件详情", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "findByTsCode")
    public ResponseEntity<?> findByTsCode(@ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "", required = false) Long tsCode) {
        return ResponseEntity.ok(fundInService.findBusiness(tsCode));
    }

    /**
      * 查看资金流水 on 2019/9/5 9:57
      *
      * @param tsCode tsCode
      * @return ResponseEntity<?>
      */
    @ApiOperation(value = "查看资金流水", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "queryCapitalFlow")
    public ResponseEntity<?> queryCapitalFlow(@ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "", required = false) Long tsCode,
                                              @ApiParam(name = "state", value = "状态:传入出账不查询的状态") @RequestParam(defaultValue = "", required = false) String state) {
        return ResponseEntity.ok(fundInService.queryCapitalFlow(tsCode,state));
    }

    /**
     * 获取买卖双方 on 2019/9/5 9:57
     *
     * @param tsCode tsCode
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "获取买卖双方", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getRelationalPersonBank")
    public ResponseEntity<?> getRelationalPersonBank(@ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "", required = false) Long tsCode) {
        return ResponseEntity.ok(fundInService.getRelationalPersonBank(tsCode));
    }

    /**
     * 获取房屋关系人银行 on 2019/9/5 9:57
     *
     * @param relatedPersonId relatedPersonId
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "获取房屋关系人银行", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getRelationalBank")
    public ResponseEntity<?> getRelationalBank(@ApiParam(name = "relatedPersonId", value = "房屋关系人id") @RequestParam(defaultValue = "", required = false) Long relatedPersonId,
                                               @ApiParam(name = "operationType", value = "操作类型:seller(卖方),buyer(买方)") @RequestParam(defaultValue = "", required = false) String operationType) {
        return ResponseEntity.ok(fundInService.getRelationalBank(relatedPersonId,operationType));
    }

    /**
     * 关系人银行新增或修改 on 2019/9/5 9:57
     *
     * @param personBank personBank
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "关系人银行新增或修改", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping(value = "relationalPersonBankSave")
    public ResponseEntity<?> relationalPersonBankSave(@RequestBody RelationalPersonBank personBank) {
        return ResponseEntity.ok(fundInService.relationalPersonBankSave(personBank));
    }

    /**
     * 关系人银行删除 on 2019/9/5 9:57
     *
     * @param personBank personBank
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "关系人银行删除", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping(value = "relationalPersonBankDelete")
    public ResponseEntity<?> relationalPersonBankDelete(@RequestBody RelationalPersonBank personBank) {
        return ResponseEntity.ok(fundInService.relationalPersonBankDelete(personBank));
    }

    /**
     * 业务列表查询 on 2019/9/5 9:57
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "业务列表查询", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "findBusinessPage")
    public ResponseEntity<?> findBusinessPage(FindBusinessPageRequest findBusinessPageRequest) {
        return ResponseEntity.ok(fundInService.getBusinessPage(findBusinessPageRequest));
    }

    /**
     * 资金缴款-分页 on 2019/9/5 9:57
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "资金缴款-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "capitalPayment")
    public ResponseEntity<?> capitalPayment(FindBusinessPageRequest findBusinessPageRequest) {
        return ResponseEntity.ok(fundInService.capitalPayment(findBusinessPageRequest));
    }

    /**
     * 缴款入账台账-分页 on 2019/9/5 9:57
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "缴款入账台账-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "paymentAccountEntryLedgerPage")
    public ResponseEntity<?> paymentAccountEntryLedgerPage(@RequestParam(defaultValue = "1") int pn,
                                                           @RequestParam(defaultValue = "30") int pageSize,
                                                           PaymentAccountEntryLedgerPageRequest request) {
        return ResponseEntity.ok(fundInService.paymentAccountEntryLedgerPage(pn,pageSize,request));
    }

    /**
     * 划款出账台账-分页 on 2019/9/5 9:57
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "划款出账台账-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "drawMoneyOutAccountLedgerPage")
    public ResponseEntity<?> drawMoneyOutAccountLedgerPage(@RequestParam(defaultValue = "1") int pn,
                                                           @RequestParam(defaultValue = "30") int pageSize,
                                                           DrawMoneyOutAccountLedgerPageRequest request) {
        return ResponseEntity.ok(fundInService.drawMoneyOutAccountLedgerPage(pn,pageSize,request));
    }

    /**
     * 根据fcode查询fundin on 2019/9/5 9:57
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "根据fcode查询fundin", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getFundInByFCode")
    public ResponseEntity<?> getFundInByFCode(@ApiParam(name = "fCode", value = "入账Id") @RequestParam(defaultValue = "", required = false) Long fCode) {
        return ResponseEntity.ok(fundInService.getFundInByFCode(fCode));
    }
}
